/**
 * 
 */
package com.furschina.struts2.portal;

import java.util.Collection;
import java.util.List;

import javax.validation.Valid;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.InterceptorRefs;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.stereotype.Controller;

import cn.wooshai.core.struts2.PaginationAware;
import cn.wooshai.core.struts2.WooshaiAction;
import cn.wooshai.core.vo.PageModel;

import com.furschina.Constants;
import com.furschina.model.Article;
import com.furschina.service.ArticleService;
import com.furschina.struts2.BaseAction;
import com.furschina.vo.ArticlePage;
import com.furschina.vo.ImageModel;

/**
 * 
 * @author zyc
 *
 */
@Controller("portal/article")
@InterceptorRefs({ @InterceptorRef(Constants.DEFAULT_STACK_REF),
		@InterceptorRef(Constants.VALIDATOR_REF) })
@Result(name = WooshaiAction.SUCCESS, type = "redirect", location = "/portal/article.xhtml")
public class ArticleAction extends BaseAction implements PaginationAware {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -4290038855486313071L;
	
	static Log LOG = LogFactory.getLog(ArticleAction.class);
	
	@Valid
	private Article model;
	private Long id;
	private Collection<Article> list;
	private ArticlePage pm = new ArticlePage();
	private ArticleService articleService;
	private List<ImageModel> images;
	
	/**
	 * @return the images
	 */
	public List<ImageModel> getImages() {
		return images;
	}

	/**
	 * @param images the images to set
	 */
	public void setImages(List<ImageModel> images) {
		this.images = images;
	}
	
	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @return the list
	 */
	public Collection<Article> getList() {
		return list;
	}

	/**
	 * @param list the list to set
	 */
	public void setList(Collection<Article> list) {
		this.list = list;
	}

	/**
	 * @param model the model to set
	 */
	public void setModel(Article model) {
		this.model = model;
	}

	public void setArticleService(ArticleService articleService) {
		this.articleService = articleService;
	}
	
	public Article getModel() {
		return this.model;
	}

	@Override
	public PageModel getPm() {
		return pm;
	}

	@Override
	public void setPage(int page) {
		this.pm.setPage(page);
	}
	
	public String index() {
		list = articleService.findByChannel(pm);
		return INDEX;
	}
	
	public String show() {
		this.model = this.articleService.findForView(id);
		return SHOW;
	}
	
	public String create() {
		model.setCreator(getUser());
		this.articleService.create(model);
		return SUCCESS;
	}
	
	public String update(){
		this.articleService.update(model);
		return SUCCESS;
	}
	
	public String include(){
		this.articleService.findByChannel(pm);
		return null;
	}

}
